package com.gis.utils;

import java.util.Date;
import java.util.HashMap;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

public class JWTUtils {
    private static final long EXPIRE_TIME= 10 * 60 * 60 * 1000;
    private static final String TOKEN_SECRET="xiaoyangkou";

    public static String GetToken(HashMap<String, Object> claims) {    
        JwtBuilder builder = Jwts.builder()
        .setIssuedAt(new Date())
        .setExpiration(new Date(System.currentTimeMillis() + EXPIRE_TIME))
        .signWith(SignatureAlgorithm.HS256, TOKEN_SECRET);
        builder.addClaims(claims);
        return builder.compact();
    }

    public static Claims parseToken(String token) {
        Claims claims = Jwts.parser()
                .setSigningKey("xiaoyangkou")
                .parseClaimsJws(token)
                .getBody();
        return claims;
        // System.out.println(claims);
    }
}
